package com.ruoyi.web.controller.memberManagement;


import java.util.List;
import javax.servlet.http.HttpServletResponse;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.MemberLevelDiscount;
import com.ruoyi.system.service.IMemberLevelDiscountService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 会员等级折扣管理（存储会员等级、折扣规则及特殊规则）Controller
 *
 * @author ruoyi
 * @date 2025-05-14
 */
@Api(tags="会员等级折扣管理")
@RestController
@RequestMapping("/system/memberLevelDiscount")
public class MemberLevelDiscountController extends BaseController
{
    @Autowired
    private IMemberLevelDiscountService memberLevelDiscountService;

    /**
     * 查询会员等级折扣管理列表
     */
    @ApiOperation("查询会员等级折扣管理列表")
    @PreAuthorize("@ss.hasPermi('system:discount:list')")
    @GetMapping("/list")
    public TableDataInfo list(MemberLevelDiscount memberLevelDiscount)
    {
        startPage();
        List<MemberLevelDiscount> list = memberLevelDiscountService.selectMemberLevelDiscountList(memberLevelDiscount);
        return getDataTable(list);
    }

    /**
     * 导出会员等级折扣管理列表
     */
    @ApiOperation("导出会员等级折扣管理列表")
    @PreAuthorize("@ss.hasPermi('system:discount:export')")
    @Log(title = "会员等级折扣管理（存储会员等级、折扣规则及特殊规则）", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, MemberLevelDiscount memberLevelDiscount)
    {
        List<MemberLevelDiscount> list = memberLevelDiscountService.selectMemberLevelDiscountList(memberLevelDiscount);
        ExcelUtil<MemberLevelDiscount> util = new ExcelUtil<MemberLevelDiscount>(MemberLevelDiscount.class);
        util.exportExcel(response, list, "会员等级折扣管理（存储会员等级、折扣规则及特殊规则）数据");
    }

    /**
     * 获取会员等级折扣管理
     */
    @ApiOperation("获取会员等级折扣管理")
    @PreAuthorize("@ss.hasPermi('system:discount:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(memberLevelDiscountService.selectMemberLevelDiscountById(id));
    }

    /**
     * 新增会员等级折扣管理列表
     */
    @ApiOperation("新增会员等级折扣管理列表")
    @PreAuthorize("@ss.hasPermi('system:discount:add')")
    @Log(title = "会员等级折扣管理（存储会员等级、折扣规则及特殊规则）", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody MemberLevelDiscount memberLevelDiscount)
    {
        return toAjax(memberLevelDiscountService.insertMemberLevelDiscount(memberLevelDiscount));
    }

    /**
     * 修改会员等级折扣管理列表
     */
    @ApiOperation("修改会员等级折扣管理列表")
    @PreAuthorize("@ss.hasPermi('system:discount:edit')")
    @Log(title = "会员等级折扣管理（存储会员等级、折扣规则及特殊规则）", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody MemberLevelDiscount memberLevelDiscount)
    {
        return toAjax(memberLevelDiscountService.updateMemberLevelDiscount(memberLevelDiscount));
    }

    /**
     * 删除会员等级折扣管理列表
     */
    @ApiOperation("删除会员等级折扣管理列表")
    @PreAuthorize("@ss.hasPermi('system:discount:remove')")
    @Log(title = "会员等级折扣管理（存储会员等级、折扣规则及特殊规则）", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(memberLevelDiscountService.deleteMemberLevelDiscountByIds(ids));
    }
}
